/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.common.ui.dijit;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2012-11-21
 */
public class TreeNode {
    // node id
    private String id = "";
    // node name
    private String name = "";
    private String type = "";
    // parent id
    private String _reference = "";
    // extra properties
    private String url = "";
    private boolean checked = false;
    // child nodes list
    private List<Map<?, ?>> children = new ArrayList<Map<?, ?>>();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String get_reference() {
        return _reference;
    }

    public void set_reference(String _reference) {
        this._reference = _reference;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<Map<?, ?>> getChildren() {
        return children;
    }

    public void setChildren(List<Map<?, ?>> children) {
        this.children = children;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public static void main(String[] args) throws Exception {
        TreeNode treeNode = new TreeNode();
        treeNode.setId("01");
        treeNode.setName("John");
        treeNode.set_reference("00");
        treeNode.setUrl("http://cn.bing.com");
        Map<String, String> referMap = new HashMap<String, String>();
        referMap.put("_reference", treeNode.get_reference());
        treeNode.getChildren().add(referMap);
        Map<String, String> referMap1 = new HashMap<String, String>();
        referMap1.put("_reference", "01");
        treeNode.getChildren().add(referMap1);
        Map<?, ?> map = BeanUtils.describe(treeNode);
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            if (entry.getValue() == null) {
                map.remove(entry.getKey());
            }
        }
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }
}
